package likou.duoxianc;

import java.util.function.IntConsumer;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2021/10/20 15:58
 */
public class _1195 {
    private int n;
    static int i = 1;

    public _1195(int n) {
        this.n = n;
    }

    // printFizz.run() outputs "fizz".
    public void fizz(Runnable printFizz) throws InterruptedException {
        while (i % 3 != 0 || i % 5 == 0) {
            Thread.yield();
        }
        System.out.println(",fizz");
        i++;
    }

    // printBuzz.run() outputs "buzz".
    public void buzz(Runnable printBuzz) throws InterruptedException {
        while (i % 5 != 0 || i % 3 == 0) {
            Thread.yield();
        }
        System.out.println(",buzz");
        i++;
    }

    // printFizzBuzz.run() outputs "fizzbuzz".
    public void fizzbuzz(Runnable printFizzBuzz) throws InterruptedException {
        while (i % 5 != 0 || i % 3 != 0) {
            Thread.yield();
        }
        System.out.println(",fizzbuzz");
        i++;
    }

    // printNumber.accept(x) outputs "x", where x is an integer.
    public void number(IntConsumer printNumber) throws InterruptedException {
        while (i % 5 == 0 || i % 3 == 0) {
            Thread.yield();
        }
        if (i == 1) System.out.println(i);
        else System.out.println("," + i);
        i++;
    }

    public static void main(String[] args) {
        _1195 o = new _1195(10);
    }
}
